package cn.sq.musicserver.utils;


import java.util.Collection;

/**
 * Created with IntelliJ IDEA.
 * User: SQ
 * Date: 2020/11/17
 * Time: 17:28
 * Description:
 */
public class ListUtils {
    /**
     * 转换Collection所有元素(通过toString())为String, 中间以 separator分隔。
     */
    public static String convertToString(final Collection collection, final String separator) {
        return org.apache.commons.lang3.StringUtils.join(collection, separator);
    }

    /**
     * 转换Collection所有元素(通过toString())为String, 每个元素的前面加入prefix，后面加入postfix，如<div>mymessage</div>。
     */
    public static String convertToString(final Collection collection, final String prefix, final String postfix) {
        StringBuilder builder = new StringBuilder();
        for (Object o : collection) {
            builder.append(prefix).append(o).append(postfix);
        }
        return builder.toString();
    }
}
